export function guid() {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
    let r = Math.random() * 16 | 0,
      v = c === 'x' ? r : (r & 0x3 | 0x8);
    return v.toString(16);
  }).replaceAll(/-/g, '');
}

export function isEmpty(obj) {
  if (!obj || obj === '' || (Array.isArray(obj) && obj.length === 0)) return true;
  if (typeof obj === 'object' && Object.keys(obj).length === 0) return true;
  return false;
}


//防止抖动
export class AntiJitter {
  timeout = 300;
  timer = null;

  constructor(callback = () => {}, timeout = 300) {
    this.timeout = timeout;
    this.callback = callback;
  }

  invoke() {
    if (this.timer) {
      clearTimeout(this.timer);
    }

    this.timer = setTimeout(() => this.callback(), this.timeout);
  }

  callback = () => {
  };
}

export function createProps (type, defaultValue) {
  if (type === String) return { type: String, default: defaultValue || undefined }
  if (type === Object) return { type: Object, default: defaultValue || (() => ({})) }
  if (type === Array) return { type: Array, default: defaultValue || (() => []) }
  if (type === Function) return { type: Function, default: defaultValue || undefined }
  if (type === Boolean) return { type: Boolean, default: defaultValue || false }
  if (type === Number) return { type: Number, default: defaultValue || 0 }
}

export function createModelForVue (prop = 'value') {
  return {
    prop,
    event: 'change'
  }
}

export function defaultPagination (pageSize = 10) {
  return {
    current: 1,
    pageSize: pageSize || 10,
    pageSizeOptions: ['5', '10', '20', '30', '50', '100'],
    showTotal: (total, range) => {
      return range[0] + '-' + range[1] + ' 共' + total + '条'
    },
    showQuickJumper: true,
    showSizeChanger: true,
    total: 0
  }
}

export const createPagination = defaultPagination